Skip to content

grammar: Update to support every and in keywords in Rego v1 syntax - #210

Merged
charlieegan3 merged 3 commits into
open-policy-agent:masterfrom
SeanLedford:s_ledford/grammar-every-and-in-support
Aug 11, 2026
Merged

grammar: Update to support every and in keywords in Rego v1 syntax#210
charlieegan3 merged 3 commits into
open-policy-agent:masterfrom
SeanLedford:s_ledford/grammar-every-and-in-support

Conversation

@SeanLedford

Copy link
Copy Markdown
Contributor

This PR updates the Rego.bnf grammar to support modern Rego v1 syntax in rule bodies. Specifically, supporting every and in keywords. The lack of support for these keywords and their related syntax was causing parser errors in Rego v1 files.

Description

Before:

Screenshot 2026-06-23 at 2 41 29 AM

After:

image

Comment thread src/main/grammar/Rego.bnf Outdated
ref-arg-brack ::= "[" ( expr | "_" ) "]"
ref-arg-dot ::= "." var
var ::= ASCII_LETTER | "contains"
var ::= ASCII_LETTER | "contains" | "in"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this so that in v0 code we show in correctly if it's a var? Do we need to do the same for every/some?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes exactly, from what I saw some was the only keyword reserved in v0, so technically the others could be used as vars. I added every and if here as well, as well as a test

Comment thread src/main/grammar/Rego.bnf Outdated
literal ::= ( every-decl | some-decl | literal-expr | "not" literal-expr ) with-modifier*
with-modifier ::= "with" term "as" term
some-decl ::= "some" var ( "," var )*
some-decl ::= "some" var ( "," var )* ( "in" expr )?

@charlieegan3 charlieegan3 Jun 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

( "," var )* is there a reason for 0 or more here? I think we can have 1 or 2.

And then for every, we can have 1, 2 as well.

@SeanLedford SeanLedford Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good catch, this rule originally matched some followed by any number of vars for declaration, just added a different rule for the some x,y in foo case to properly match 1 or 2 vars

@charlieegan3 charlieegan3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM pending some responses on the comments

@charlieegan3

Copy link
Copy Markdown
Contributor

Might be nice to make a short CL update too to it's shown in the next release.

Signed-off-by: seanledford <s_ledford@apple.com>
Signed-off-by: seanledford <s_ledford@apple.com>
Signed-off-by: seanledford <s_ledford@apple.com>
@SeanLedford
SeanLedford force-pushed the s_ledford/grammar-every-and-in-support branch from 4221b8a to 774c7db Compare July 6, 2026 06:01
@charlieegan3
charlieegan3 merged commit 8f91de8 into open-policy-agent:master Aug 11, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants